package ch01;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;

/**
 * @author Jane
 * @date 2024-03-15 15:14
 */

public class TestStudent {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException {
       /* Class c1 = new Student().getClass();

        Class c2 = Student.class;

        Class c3=Class.forName("ch01.Student");

        System.out.println(c1==c2);
        System.out.println(c2==c3);
        System.out.println(c3==c1);*/

        Class c2 = Student.class;
       /* System.out.println(c2.getName());  //包.类
        System.out.println(c2.getSimpleName());//类*/

        int modifiers = c2.getModifiers();

       /* System.out.println(Arrays.toString(c2.getConstructors()));//public
        System.out.println(Arrays.toString(c2.getDeclaredConstructors()));

        //指定参数获取构造函数
        System.out.println(c2.getDeclaredConstructor(int.class,String.class));
*/

        //属性
       /* Field[] fields = c2.getDeclaredFields();
        for (Field f: fields) {
            System.out.println(f.getName());
        }

        Field stuName = c2.getDeclaredField("stuName");
        System.out.println(stuName.getName());*/

        //方法
        Method[] methods = c2.getDeclaredMethods();
        for (Method m:methods) {
//            System.out.println(m.getName());
            System.out.printf("方法名称:%s 返回值类型:%s 参数数量:%s 参数列表:"
                                ,m.getName()
                                ,m.getReturnType()
                                ,m.getParameterCount()
            );
            Class<?>[] types = m.getParameterTypes();
            for (Class c:types) {
                System.out.printf("%s\t",c.getName());
            }
            System.out.println();
        }


    /*    Method setStuNo = c2.getMethod("setStuNo");
        System.out.println(setStuNo.getName());*/

    }
}
